# encoding: utf-8

#切片 起始index，结束index-1 ,步长
L = ['NO1','NO2','NO3','NO4','NO5','NO6','NO7','NO8']
print L[-2:]
str1 = '计划任务.xml'
print str1[:len(str1)-len('.xml')]

#迭代
from collections import Iterable #引入命名空间？
print isinstance('abc', Iterable)
dic = {'key1':2,'key2':9}
for key in dic:
	print key
for item in dic.itervalues():
	print item
for k,v in dic.iteritems():
	print k,v
#好像只有foreach循环 要实现for循环的话
for i,key in enumerate(dic):
	print i,key

#列表生成式
import os
print [d for d in os.listdir('.')]
#多层列表生成式
l1 = ['x','y','z']
l2 = ['a','b','c']
def fit(a,b):
	print a,b
print [fit(a,b) for a in l1 for b in l2]

# 生成器
# 由于循环时计算，所以占用内存相对列表及其他较少
# 小括号+列表表达式
g= (d for d in os.listdir('.'))
print g
for item in g:
	print item
#定义生成器 yield
def fib(tMax):
	n,a,b = 0,0,1
	while n< tMax:
		yield b
		a,b = b,a+b
		n = n + 1

for item in fib(6):
	print item